package com.example.demo_1106.Controller;

import com.example.demo_1106.entity.Userinfo;
import com.example.demo_1106.service.UserinfoService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户信息控制器
 *
 * @author kongke
 * @date 2023/07/23
 */
@RestController
@RequestMapping("/userinfo")
public class UserinfoController {

    @Autowired
    UserinfoService userinfoService;

    /**
     * 查询用户
     *
     * @param account 账户（userLoginName）
     * @return {@link List}<{@link Userinfo}>
     */
    @GetMapping("/select")
    public List<Userinfo> selectUser(@RequestParam("userLoginName")String account){
        return userinfoService.getUser(account);
    }

    /**
     * 添加用户
     *
     * @param user 用户
     * @return boolean
     */
    @PostMapping("/add")
    public boolean addUser(@RequestBody Userinfo user){
        return userinfoService.addUser(user);
    }

    /**
     * 删除用户
     *
     * @param account 账户
     * @return boolean
     */
    @DeleteMapping()
    public boolean delUser(@RequestParam("UserLoginName") String account){
        return userinfoService.delUser(account);
    }

    /**
     * 更新用户
     *
     * @param user    用户
     * @return boolean
     */
    @PutMapping("/update")
    public boolean updateUser(@RequestBody Userinfo user){
        return userinfoService.updateUser(user);
    }

}
